using System;
namespace cs5643.rigidbody
{

    /** 
     * A hashable int representation of a pair of indexed rigid
     * bodies.  
     * 
     * @author Doug James, March 2007.
     */
    public class BodyPair
    {

        /** Body "i" index */
        public int i { get; private set; }

        /** Body "j" index */
        public int j { get; private set; }

        /** Hashcode for body pair: hash(i,j)=hash(j,i). */
        public int hash { get; private set; }

        public BodyPair(int i, int j)
        {
            if (i == j) throw new ArgumentException("i==j not allowed");

            this.i = i;
            this.j = j;

            int min = Math.Min(i, j);
            int max = Math.Max(i, j);

            if (max >= (int)Int16.MaxValue)
                throw new ArgumentException
                ("Can't handle body indices > Short.MAX_VALUE=" + Int16.MaxValue +
                 ", but max(i,j) was " + max);

            hash = (int)Int16.MaxValue * min + max;
        }
    }
}